package com.xin.di.uav.applet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xin.di.uav.applet.mapper.DictionaryMapper;
import com.xin.di.uav.applet.po.Dictionary;
import com.xin.di.uav.applet.service.IDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 设置字典表 服务实现类
 * </p>
 *
 * @author LTQ
 * @since 2023-09-04
 */
@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements IDictionaryService {

    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Override
    public Dictionary getBySubject(String subject) {
        QueryWrapper<Dictionary> dictionaryQueryWrapper = new QueryWrapper<>();
        dictionaryQueryWrapper.eq("subject", subject);
        dictionaryQueryWrapper.eq("enable", true);
        return dictionaryMapper.selectOne(dictionaryQueryWrapper);
    }

    @Override
    public List<Dictionary> getListBySubject(String subject) {
        QueryWrapper<Dictionary> dictionaryQueryWrapper = new QueryWrapper<>();
        dictionaryQueryWrapper.like("subject", subject);
        dictionaryQueryWrapper.eq("enable", true);
        dictionaryQueryWrapper.orderByAsc("sort");
        List<Dictionary> dictionaries = dictionaryMapper.selectList(dictionaryQueryWrapper);
        return dictionaries;
    }
}
